<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Document</title>
		<style type="text/css">
			*{
				margin:0;
				padding:0;
			}
			html,body{
				height:100%;
			}
			#box{
				height:100%;
			}
		</style>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=TFUzKanYlqx7eCkE7SceTqgRuVOkNhHR"></script>
	</head>
	<body>
		
		<div id='box'></div>
		<script type="text/javascript">
			var x =0,y=0;
			
				//console.log( navigator.geolocation );

					// 百度地图API功能
	var map = new BMap.Map("box");
	var point = new BMap.Point(112.8831780658,28.2358853700);
	map.centerAndZoom(point,17);
	map.enableScrollWheelZoom(true);
	
	// 用经纬度设置地图中心点
	theLocation();
	function theLocation(){
			map.clearOverlays(); 
			var marker = new BMap.Marker(point);  // 创建标注
			map.addOverlay(marker);              // 将标注添加到地图中
			marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
			map.panTo(point);      
	}

	

/*					
	// 百度地图API功能
	var map = new BMap.Map("box");
	var point = new BMap.Point(112.8769719304,28.2303174754);
	map.centerAndZoom(point,12);

	var geolocation = new BMap.Geolocation();

				geolocation.getCurrentPosition(function(position){
					//x = position.coords.latitude;
					//y = position.coords.longitude;
					//box.innerHTML += '经度：'+x;
					//box.innerHTML += '纬度：'+y;
					//console.log(y,x);
					// 百度地图API功能
	
	var map = new BMap.Map("box");    // 创建Map实例
	var point = new BMap.Point(y, x);
	map.centerAndZoom(point, 15);  // 初始化地图,设置中心点坐标和地图级别
	map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
	map.setCurrentCity("长沙");          // 设置地图显示的城市 此项是必须设置的
	map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
	*/


		
			
		
/*
	var mk = new BMap.Marker(position.point);
			map.addOverlay(mk);
			map.panTo(position.point);
			console.log('您的位置：'+position.point.lng+','+position.point.lat);
	map.enableScrollWheelZoom(true);
	// 覆盖区域图层测试
	map.addTileLayer(new BMap.PanoramaCoverageLayer());

	var stCtrl = new BMap.PanoramaControl(); //构造全景控件
	stCtrl.setOffset(new BMap.Size(20, 20));
	map.addControl(stCtrl);//添加全景控件


	var myP1 = new BMap.Point(112.8769719304 ,28.2303174754);    //起点
	var myP2 = new BMap.Point(112.8769719304 ,28.2303174754);    //终点
	var myIcon = new BMap.Icon("http://lbsyun.baidu.com/jsdemo/img/Mario.png", new BMap.Size(32, 70), {    //小车图片
		//offset: new BMap.Size(0, -5),    //相当于CSS精灵
		imageOffset: new BMap.Size(0, 0)    //图片的偏移量。为了是图片底部中心对准坐标点。
	  });
	var driving2 = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});    //驾车实例
	driving2.search(myP1, myP2);    //显示一条公交线路

	window.run = function (){
		var driving = new BMap.DrivingRoute(map);    //驾车实例
		driving.search(myP1, myP2);
		driving.setSearchCompleteCallback(function(){
			var pts = driving.getResults().getPlan(0).getRoute(0).getPath();    //通过驾车实例，获得一系列点的数组
			var paths = pts.length;    //获得有几个点

			var carMk = new BMap.Marker(pts[0],{icon:myIcon});
			map.addOverlay(carMk);
			i=0;
			function resetMkPoint(i){
				carMk.setPosition(pts[i]);
				if(i < paths){
					setTimeout(function(){
						i++;
						resetMkPoint(i);
					},100);
				}
			}
			setTimeout(function(){
				resetMkPoint(5);
			},100)

		});
	}

	setTimeout(function(){
		run();
	},1500);
*/

/*	
	
	var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
	var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
	var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}); //右上角，仅包含平移和缩放按钮
	
	add_control();
	//delete_control();
	//添加控件和比例尺
	function add_control(){
		map.addControl(top_left_control);        
		map.addControl(top_left_navigation);     
		map.addControl(top_right_navigation);    
	}
	//移除控件和比例尺
	function delete_control(){
		map.removeControl(top_left_control);     
		map.removeControl(top_left_navigation);  
		map.removeControl(top_right_navigation); 
	}

})*/
				
			
		</script>
	</body>
</html>
